package bod.engine;

public class Environment {

	public static final int		SPRING		= 0;
	public static final int		SUMMER		= 1;
	public static final int		FALL		= 2;
	public static final int		WINTER		= 3;

	private static final int	DAY_TICKS	= 6000;
	private static final int	TICK_DAWN	= 0;
	private static final int	TICK_DAY	= DAY_TICKS / 10;
	private static final int	TICK_DUSK	= DAY_TICKS * 5 / 10;
	private static final int	TICK_NIGHT	= DAY_TICKS * 6 / 10;
	private static final int	YEAR_DAYS	= DAY_TICKS * 12;
	private static final int	SEASON_DAYS	= YEAR_DAYS / 4;

	private int					ticks;
	private int					darkness;
	private int					days;
	private int					wind;

	public Environment() {
		this.ticks = TICK_DAY;
		this.days = 0;
		this.wind = 0;
	}

	public void tick() {
		this.ticks++;
		if (this.ticks > DAY_TICKS) {
			this.ticks = 0;
			this.days++;
			if (this.days > YEAR_DAYS) {
				this.days = 0;
			}
		}
		if (this.ticks < TICK_DAY) {
			this.darkness = 200 - (this.ticks - TICK_DAWN) * 2000 / DAY_TICKS;
		} else if (this.ticks < TICK_DUSK) {
			this.darkness = 0;
		} else if (this.ticks < TICK_NIGHT) {
			this.darkness = (this.ticks - TICK_DUSK) * 2000 / DAY_TICKS;
		} else {
			this.darkness = 200;
		}
	}

	public boolean isDay() {
		return this.ticks > TICK_DAY && this.ticks < TICK_DUSK;
	}

	public int getDarkness() {
		return this.darkness;
	}

	public int getSeason() {
		return this.days / SEASON_DAYS;
	}

	public int getWind() {
		return this.wind;
	}

}